<?
//modifies code
    include('conn.php');
    include('protect.php');
    include('gettopmenu.php');
	    
	session_start();
	$msg='';
  	
 //   if($_REQUEST['up']=='true' and isset($_REQUEST['id']))
//	{
//		$id=$_REQUEST['id'];
//		$sqledit="select * from usermast where status = 0 and user_name='".$id."'";
//		include('conn.php');
//		$resedit=mysql_query($sqledit);
//		$rowedit=mysql_fetch_assoc($resedit);		
//	}
    
        
    if($_REQUEST['submit']=='Save Record')
	{
		$user_name=$_REQUEST['user_name'];
		$user_id=$_REQUEST['user_id'];
        $usergroup=$_REQUEST['usergroup'];
		$user_pass=$_REQUEST['user_pass'];
		$email_id=$_REQUEST['email_id'];
		$created_by=$_SESSION['username'];
		$user_passcnf = $_REQUEST['user_passcnf'];		
//		if ($user_passcnf = $user_pass)
//		{
			$sqlc="select count(*) cnt from usermast where user_id='".$user_id."'";
			$resc=mysql_query($sqlc);
			$rowc=mysql_fetch_assoc($resc);
			if($rowc['cnt']==0)
			{
				$sql="insert into usermast(user_name,user_id,usergroup,user_pass,email_id,created_by,create_date)
						values('".$user_name."','".$user_id."','".$usergroup."','".md5($user_pass)."','".$email_id."','".$created_by."',sysdate())";
				$res=mysql_query($sql);
				if($res)
					$msg='Record saved successfully';			
			}
			else
			{
				$msg='Record Already Exist';			
			}
		}	
//		else
//			{ 
//			$msg = 'Password and Confirm Password does not Match'
//		}
?>
<script type="text/javascript" src="addusermain.js"></script>
 <script language="javascript">
 function SearchCtrl($scope, $http) {
        $scope.url = 'saveuser.php'; // The url of our search
        // The function that will be executed on button click (ng-click="search()")
        $scope.search = function() {
            // Create the http post request
            // the data holds the keywords
            // The request is a JSON request.  i want the data in $_POST
			$http.post($scope.url, { "user_name" : $scope.user_name,"user_id" : $scope.user_id,"user_pass" : $scope.user_pass,"email_id" : $scope.email_id, "usergroup" : $scope.usergroup}).
            success(function(data, status) {
                $scope.status = status;
                $scope.data = data;
                $scope.result = data; // Show result from server in our <pre></pre> element
            }).
            error(function(data, status) {
                $scope.data = data || "Request failed";
                $scope.status = status;         
            });
        };
			//alert(" ");
}


  function deleteuser(name0)
       {
        alert(" Reference no to be deleted is: " + name0);

    if (confirm('Do you really want to delete this record?'))
      {
		$.post( "adduserdelete.php?", { user_name: name0})
        	.done(function( data )
                { 
                  alert("Record Deleted is  " + name0);
                 });
          }
	}
        

function adduseredit(Referenceno,param2)
{
    //alert(name);
	window.location.href = Referenceno;	
}

</script>
<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">User Management / Add User </label></td>
<div  align="center">
			<div ng-controller="SearchCtrl">
			<table  cellpadding="4" id="box-table-a" cellspacing="4" border="1" width="650" bgcolor="#000000" style="background-color:#DFEBF9;">
				<tr><td colspan="3" align="center" style="text-align:center; color:#FF0000;">{{result}}</td></tr>
				<tr>
				  <td colspan="3" align="center" style="text-align:center; font-weight:bold;">Add User</td>
				</tr>
				<tr bgcolor="#FFFFFF">
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Name</label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
					<input type="text" id="user_name" name="user_name" class="smallInput" required= "" ng-model="user_name" placeholder="User Name" style="width:280px; text-align:left; font-size:12px; font-weight:bold;" />
				</tr>
				<tr bgcolor="#FFFFFF">
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Email Id </label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
					<input type="text" id="email_id" name="email_id" class="smallInput" required= "" ng-model="email_id" placeholder="Email Id" style="width:280px; text-align:left; font-size:12px; font-weight:bold;" />
				</tr>
				<tr bgcolor="#FFFFFF">
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">User Id <br />
					</label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
					<input type="text" id="user_id" name="user_id" class="smallInput" required= "" ng-model="user_id" placeholder="Login Id" style="width:280px; text-align:left; font-size:12px; font-weight:bold;" />
					</td>
				</tr>
                    <tr bgcolor="#FFFFFF">
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">User Group <br />
					</label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
				
                <select name="usergroup" id="usergroup" class="smallInput" required= "" ng-model="usergroup" placeholder="usergroup" style="width:280px; text-align:left; font-size:12px; font-weight:bold;" />
		        		<option value="OPSUSER">OPSUSER</option>
    					<option value="ADMIN">ADMIN</option>
				</select>
                </td>
				                
                </tr>
				<tr bgcolor="#FFFFFF">
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Password</label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
					<input  type="password" id="user_pass" name="user_pass" class="smallInput" required= "" ng-model="user_pass" placeholder="Enter Password" style="width:280px; text-align:left; font-size:12px; font-weight:bold;" />
					</td>
				</tr>
				<tr bgcolor="#FFFFFF">
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Confirm Password </label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
					<input  type="password" id="user_passcnf" name="user_passcnf" class="smallInput" required= "" ng-model="user_passcnf" placeholder="Confirm Password" style="width:280px; text-align:left; font-size:12px; font-weight:bold;" />
					</td>
				</tr>
				<tr>
					<td align="center" colspan="3" style="background-color:#BBE2EE">
					<button type="submit" class="btn" ng-click="search();">Save</button>
					</td>
				</tr>
			</table>
		</div>
        <div  ng-controller="adduser" id="adduser">
    			<div> <a ng-click="refreshGrid()"> Refresh Grid </a></div>
		        <div class="gridStyle1" ng-grid="gridOptions"></div>
			</div>
        
</div>
</body>
</html>
